package com.xuyuan.mybatis.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xuyuan.agent.entity.Student;
import com.xuyuan.mybatis.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PageHelperServiceManager {

    @Autowired
    private StudentMapper studentMapper;

    public void test() {
        // 数据库物理分页
        PageHelper.startPage(1, 3);
        List<Student> students = studentMapper.selectAll();
        System.out.println(students);

        // 将查询的对象封装到PageInfo下就可以获取分页的各种数据
        PageInfo<Student> pageInfo = new PageInfo<>(students);
        int pageNum = pageInfo.getPageNum();// 获取当前页
        int pages = pageInfo.getPages();// 获取总页数
        int pageSize1 = pageInfo.getPageSize();// 获取每页大小
        int size = pageInfo.getSize();// 获取当前页的记录数
        long total = pageInfo.getTotal();// 获取总记录数
        // 就是上面的查询结果
        List<Student> list = pageInfo.getList();// 获取当前页的内容
        System.out.println(list);

    }

}
